package org.vectrics.user;

import java.util.Comparator;
import org.apache.log4j.Logger;


public class UserPrivilegeComparator implements Comparator {
	
	private transient static Logger log = Logger.getLogger(UserPrivilegeComparator.class);
	
	public UserPrivilegeComparator() {
		super();		
	}
	
	public int compare(Object o1, Object o2) {
		log.debug("compare() called");
		int result = 0;
		//log.info("compare() - o1 =  " + o1.toString() + "  o2 = " + o2.toString());
		UserPrivilege role1 = (UserPrivilege)o1;
		UserPrivilege role2 = (UserPrivilege)o2;
		
		log.debug("compare() - comparing user");
		result = role1.getPerson().getId().compareTo(role2.getPerson().getId());
		if (result == 0) {
			log.debug("compare() - user is the same, comparing roles");
			result = role1.getPrivilegeType().getCode().compareTo(role2.getPrivilegeType().getCode());
		}
		
		return result;
	}

}